Skip to content

fix(server-nestjs/sonarqube): harden sonarqube reconciliation with strict key matching and idempotent init#2299

Merged
KepoParis merged 1 commit into
mainfrom
fix/sonarqube-reconciliation-hardening
Jul 15, 2026
Merged

fix(server-nestjs/sonarqube): harden sonarqube reconciliation with strict key matching and idempotent init#2299
KepoParis merged 1 commit into
mainfrom
fix/sonarqube-reconciliation-hardening

Conversation

@KepoParis

Copy link
Copy Markdown
Contributor

Issues liées

Issues numéro: N/A


Quel est le comportement actuel ?

  • L'authentification vers l'API SonarQube encodait le token en base64 (token:) avant de l'envoyer en Bearer, ce qui ne correspond pas au format attendu par SonarQube.
  • À l'initialisation, le template de permissions Forge Default était recréé systématiquement, provoquant une erreur si le template existait déjà.
  • Les réponses HTTP en erreur (statut >= 400) de l'API SonarQube n'étaient pas remontées comme des erreurs.
  • La réconciliation identifiait les projets SonarQube appartenant à la console via un simple préfixe (<slug>-<repo>-), ce qui pouvait entraîner la suppression de projets créés manuellement ou appartenant à un autre projet dont le slug est un préfixe.

Quel est le nouveau comportement ?

  • Le token SonarQube est envoyé tel quel en Bearer, sans encodage base64.
  • L'initialisation est idempotente : le template de permissions est recherché via permissions/search_templates et n'est créé que s'il n'existe pas.
  • La permission globale scan est ajoutée au groupe admin (GLOBAL_ADMIN_PERMISSIONS).
  • Les réponses HTTP en erreur lèvent désormais une SonarqubeError avec le statut et les messages d'erreur retournés par l'API.
  • L'appartenance d'un projet SonarQube à la console est vérifiée en recalculant la clé complète (avec son suffixe HMAC) via generateProjectKey : les projets non gérés par la console ne sont plus jamais supprimés.
  • generateProjectKey et generateRandomPassword sont déplacés dans apps/server-nestjs/src/utils/crypto.ts (implémentation identique octet par octet à celle de @cpn-console/hooks pour préserver la compatibilité des clés existantes).

Cette PR introduit-elle un breaking change ?

Non. La génération des clés de projet reste strictement identique à l'implémentation historique, aucune migration n'est nécessaire.

Autres informations

Tests ajoutés : idempotence de la création du template de permissions, suppression des projets retirés uniquement, et non-suppression des projets dont la clé n'a pas été générée par la console.

@KepoParis KepoParis added this to the 9.20.0 milestone Jul 10, 2026
@KepoParis KepoParis self-assigned this Jul 10, 2026
@KepoParis KepoParis added the bug Something isn't working label Jul 10, 2026
@github-actions github-actions Bot added the built label Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@KepoParis KepoParis changed the title fix(server-nestjs): harden sonarqube reconciliation with strict key matching and idempotent init fix(server-nestjs/sonarqube): harden sonarqube reconciliation with strict key matching and idempotent init Jul 10, 2026
Comment thread apps/server-nestjs/src/modules/sonarqube/sonarqube.service.ts
Comment thread apps/server-nestjs/src/modules/sonarqube/sonarqube.service.ts
@KepoParis KepoParis requested a review from shikanime July 13, 2026 09:15
@KepoParis KepoParis force-pushed the fix/sonarqube-reconciliation-hardening branch from ea57522 to 478d356 Compare July 13, 2026 10:02
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@KepoParis KepoParis force-pushed the fix/sonarqube-reconciliation-hardening branch from 478d356 to abcbe85 Compare July 14, 2026 16:38
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

StephaneTrebel
StephaneTrebel previously approved these changes Jul 15, 2026

@StephaneTrebel StephaneTrebel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Là aussi il faudra une seconde passe, je pense

Comment thread apps/server-nestjs/src/modules/sonarqube/sonarqube-http-client.service.ts Outdated
Comment thread apps/server-nestjs/src/modules/sonarqube/sonarqube-http-client.service.ts Outdated
Comment thread apps/server-nestjs/src/modules/sonarqube/sonarqube.service.ts
Comment thread apps/server-nestjs/src/utils/crypto.ts
@KepoParis KepoParis force-pushed the fix/sonarqube-reconciliation-hardening branch from abcbe85 to 66a8f15 Compare July 15, 2026 09:08
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@cloud-pi-native-sonarqube

Copy link
Copy Markdown

@KepoParis KepoParis requested a review from StephaneTrebel July 15, 2026 09:15
Comment thread apps/server-nestjs/src/utils/crypto.spec.ts

@StephaneTrebel StephaneTrebel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@KepoParis KepoParis added this pull request to the merge queue Jul 15, 2026
Merged via the queue into main with commit 2686a59 Jul 15, 2026
34 checks passed
@KepoParis KepoParis deleted the fix/sonarqube-reconciliation-hardening branch July 15, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working built

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants